var promoteMoney=0;
var nums=0;
$(function () {
	slf.getUser();
    $("#promoteBtn").click(function(){
    	if(promoteMoney==0||promoteMoney=="0.00"||promoteMoney=="00.00"){
    		$(".alert1").html("您暂无可提现金额！");
    		$("#alert1").modal({
    			closeViaDimmer: false,
    		});
    	}else{
    		$('#modelPromote').modal({
    			closeViaDimmer: false,
        		onConfirm: function(options) {
        			nums++;
        			if(nums==1){
        				buttonClick(promoteMoney)
        			}
    	        },
        	});
    	}
    })
	//推广下线
	slf.ajax({
		url: "/recommendMoney/effectiveNumber",
		success: function (data) {
			console.log("获取推广返回信息")
        	console.log(data)
            if (data.res > 0) {
            	$("#promotePer").html(data.obj[0]);
				$("#promoteMoney").html(data.obj[1])
                $("#proNowMoney").html(data.obj[2])
                promoteMoney=data.obj[2];
				$(".promoteMoneys").html(promoteMoney)
            }
		}
	});
	//提现
	getSlfCash();
});

// 点击提现
function buttonClick(money1) {
	if($("input[name='money']:checked").val() == "1"||$("input[name='money']:checked").val() == 1) {
		//立方币
		var param={
			type: 1
		}
	}else if($("input[name='money']:checked").val() == "0"||$("input[name='money']:checked").val() == 0) {
		//人民币
		var param={
			type: 2
		}
	}
	slf.ajax({
		url: '/slfcash/insertSelective',
		param:param,
		success: function (data) {
			if (data.res == 1) {
				location.reload();
			} else {
				nums=0;
				alert(data.resMsg)
			}
		}
	});
	
}

// 提现记录
function getSlfCash() {
	slf.ajax({
		url: "/slfcash/getSlfCash",
		param: {
			userId: slf.user.userId
		},
		success: function (data) {
			console.log("提现记录")
			console.log(data)
			var cashHTML = '';
			if (data.res == 1&&data.obj.length>0) {
				console.log(data.obj.length)
				for (var a = 0, b = data.obj.length; a < b; a++) {
					cashHTML +='<li class="promoteMessLi">'
					cashHTML +='<span class="proTime text-left">' + data.obj[a].cashDateStr + '</span>'
					if(data.obj[a].cashType==1){
						//立方币
						cashHTML +='<span class="proTime text-center">提现：' + data.obj[a].cashMoney + '立方币</span>' 
						cashHTML +='<span class="proTime text-center">实际结算：' + data.obj[a].cashMoney + '立方币</span>'
					}else if(data.obj[a].cashType==2){
						//人民币
						cashHTML +='<span class="proTime text-center">提现：' + data.obj[a].cashMoney + '人民币</span>' 
						cashHTML +='<span class="proTime text-center">实际结算：' + data.obj[a].cashMoney + '人民币</span>'
					}
					if(data.obj[a].state==3){
					   //提现成功	
					   cashHTML +='<span class="proTime text-right">状态：<span style="color:#6DD874">已到账</span></span>' 
					}else if(data.obj[a].state==4){
						//审核中
						cashHTML +='<span class="proTime text-right">状态：<span class="text-FF0305">结算中</span></span>'
					}
					cashHTML +='</li>'
				}
			} else {
				cashHTML +='<li class="promoteMessLi" style="color:#888">暂无提现历史,快去推广吧！</li>'
			}
			$("#proDivMess").append(cashHTML)
		}
	});
}

function goPromote(){
	window.location.href='personal/extension.html?qrCode='+slf.user.qrCode+'&imgId=Extension1';
}

